<?php
//TODO:More code is needed.
require_once 'user/UserManager.php';
require_once 'GlobalSettings.php';

class LerniBasicController extends Zend_Controller_Action
{
    protected $requiredLogin = true;
	protected $defaultSessionName = null;
	protected $defaultSession = null;
	
	public function indexAction()
    {  
	   if(GlobalSettings::RELEASE_MODE)
	   {
	      $this->gotoRootPage();
		  return;
	   }
	}
	
	public function preDispatch()
	{
	   if($this->requiredLogin && $this->getCurrentUser() == NULL)
	   {
	      $this->gotoLoginPage();
	   }
	}
	
	public function getCurrentUser()
	{	    
	    //Should it from session storage?
	    return UserManager::instance()->Login(99,"anywords");
	    $session = new Zend_Session_Namespace(GlobalSettings::USER_SESSION);		
	    return $session.loginUser;
	}
	
	public function gotoLoginPage()
	{
	    $this->_redirect("/Login");
	}
	
	public function gotoRootPage()
	{  
	    $this->_redirect("/");
	}
	
	public function gotoErrorPage()
	{
	   $this->_redirect("/error");
	}
	
	public function renderError($errorMessage)
	{
	   $this->view->message = $errorMessage;
	   $this->render("error/message",NULL,true);
	}
	
	public function getDefaultSession()
	{
	   if(null == $this->defaultSession)
	   {
	      $this->defaultSession = new Zend_Session_Namespace($this->defaultSessionName);
	   }
	   
	   return $this->defaultSession;
	}
};

?>